package com.jpcc.vw.onlineRadio.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jpcc.vw.onlineRadio.R;
import com.jpcc.vw.onlineRadio.model.bean.Track;
import com.jpcc.vw.onlineRadio.utils.ViewHolderUtils;

import java.util.ArrayList;
import java.util.List;

public class PaidAlbumTracksAdapter extends BaseAdapter {

    private List<Track> tracks = new ArrayList<>();
    private Context context;

    public PaidAlbumTracksAdapter(Context c, List<Track> sources) {
        if (c != null) {
            context = c;
        }
        tracks.clear();
        tracks.addAll(sources);
    }


    @Override
    public int getCount() {
        return tracks.size();
    }

    @Override
    public Track getItem(int position) {
        return tracks.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_album_category, parent, false);
        }
        initViews(convertView, position);
        return convertView;
    }

    public void setDatas(List<Track> sources) {
        if (sources != null) {
            tracks.clear();
            tracks.addAll(sources);
            notifyDataSetChanged();
        }
    }

    private void initViews(View view, int position) {
        TextView tv_position = ViewHolderUtils.get(view, R.id.tv_position);
        TextView tv_category = ViewHolderUtils.get(view, R.id.tv_category);
        tv_position.setVisibility(View.INVISIBLE);
        tv_category.setText(tracks.get(position).getTrackTitle());
    }
}
